﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeneratorLib.DB;
using MySQLProvider.Connectios;

namespace MySQLProvider
{
    public class MySQLProvider : IDBProvider
    {
        public string DBProviderName
        {
            get { return "MySQL"; }
        }

        public IConnection CreateNew()
        {
            DBConnecter frm = new DBConnecter();
            var res= frm.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                return frm.ConnectionInfo;
            }
            else {
                return null;
            }
        }

        public IConnection CreateNew(string name, string connectStr)
        {
            return new MYSQLConnection(name, connectStr);
        }

        public bool EditConnection(IConnection connection)
        {
            var con = connection as MYSQLConnection;
            if (con == null)
            {
                return false;
            }

            DBConnecter frm = new DBConnecter();
            frm.ConnectionInfo = con;
            var res = frm.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                connection = frm.ConnectionInfo; 
                return true;
            }
            else
            {
                return false;
            }

        }

        public override string ToString()
        {
            return DBProviderName;
        }

    }
}
